#!/bin/bash
#用于文件同步前环境配置脚本

yum install -y rsync inotify-tools sshpass

ip='192.168.1.68'
host='master'
masterPasswd='password'

#新增/etc/hosts下的主机文件
grep $host /etc/hosts >/dev/null;[ $? -ne 0 ] && echo "$ip $host" >>/etc/hosts
#设置密钥登录
echo -e 'y\n' | ssh-keygen -t rsa -N '' -f $HOME/.ssh/id_rsa &>/dev/null
#复制密钥文件到机器上
sshpass -p $masterPasswd ssh-copy-id -o StrictHostKeyChecking=no root@$host &>/dev/null
mv ./syncFiles.sh /etc/init.d/autostart.sh
chmod +x /etc/init.d/autostart.sh
sh /etc/init.d/autostart.sh &>/dev/null
systemctl enable autostart.sh &>/dev/null